package com.test.nnooolwdeaer.dialog_wooden;

import static android.view.View.GONE;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.constant_wooden.Constant_wooden;

import java.util.Objects;

public class TipsDialog_wooden extends Dialog {

    private final Runnable onOkRunnable;

    private String content;

    public TipsDialog_wooden(@NonNull Context context, Runnable onOkRunnable) {
        super(context);
        this.onOkRunnable = onOkRunnable;
    }

    public TipsDialog_wooden(@NonNull Context context, Runnable onOkRunnable, String content) {
        super(context);
        this.onOkRunnable = onOkRunnable;
        this.content = content;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_tips_wooden);
        initView_wooden();
    }

    @SuppressLint("SetTextI18n")
    private void initView_wooden(){

        try {
            Objects.requireNonNull(getWindow()).setBackgroundDrawableResource(R.color.trans);
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            setCancelable(false);
        }catch (Exception e){
            if (Constant_wooden.Debug) e.printStackTrace();
        }

        View cancelBtn = findViewById(R.id.dialog_tips_btn_cancel);
        cancelBtn.setOnClickListener(v -> dismiss());

        findViewById(R.id.dialog_tips_btn_ok).setOnClickListener(v -> {
            dismiss();
            if (onOkRunnable!=null) onOkRunnable.run();
        });

        if (!TextUtils.isEmpty(content)){

            TextView contentTv = findViewById(R.id.dialog_tips_tv_content);

            contentTv.setText(content);

            cancelBtn.setVisibility(GONE);

        }

    }

}
